package com.lzs.Service.Impl;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lzs.DAO.UserDAO;
import com.lzs.PO.Page;
import com.lzs.PO.Role;
import com.lzs.PO.User;
import com.lzs.Service.UserService;
@Service("UserService")
@Transactional
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDAO userDAO;
	public User check(String username, String password) {
		User user = this.userDAO.getUser(username, password);
		return user;
	}
	@Override
	public Page<User> findUserPagelist(String keyword, Integer pageNum, Integer pageSize) {
		
		List<User> rolelist = this.userDAO.findUserList(keyword);
		
		int totalRecord = rolelist.size();

		Page page = new Page(pageNum, pageSize, totalRecord);

		int startIndex = page.getStartIndex();

		page.setList(userDAO.findUserPagelist(keyword, startIndex, pageSize));
		
		return page;
	}
	@Override
	public void addUser(User user) {
		this.userDAO.addUser(user);
		
	}
	@Override
	public void addUserRole(Map<String, Object> map) {
		this.userDAO.addUserRole(map);
		
	}
	@Override
	public Boolean countUserById(Integer userid) {
		long count = this.userDAO.countUserById(userid);
		
		return count == 0;
	}
	@Override
	public User findUserRoleById(Integer userid) {
		User user = this.userDAO.findUserRoleById(userid);
		return user;
	}
	@Override
	public void updateUser(User user) {
		this.userDAO.updateUser(user);
		
	}
	@Override
	public void updateUserRole(Map<String, Object> map) {
		
		this.userDAO.deleteUserRoleById(map);
		
		this.userDAO.addUserRole(map);
		
	}
	@Override
	public void deleteUser(Integer userid) {
		this.userDAO.deleteUser(userid);
	}
	@Override
	public void deleteUserRoleById(Map<String, Object> map) {
		this.userDAO.deleteUserRoleById(map);
		
	}

}
